import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
// element-ui
import './plugins/element';
// 全局样式
import './assets/global.css';
// axios
import axios from 'axios';
// lib-flexible
import 'lib-flexible';

axios.defaults.baseURL = 'http://127.0.0.1:3000/';
axios.interceptors.request.use(
	(config) => {
		if (localStorage.getItem('token')) {
			config.headers.Authorization = localStorage.getItem('token');
		}
		return config;
	},
	(error) => {
		return Promise.reject(error);
	}
);

// 配置请求拦截器

Vue.prototype.$axios = axios;

Vue.config.productionTip = false;

// 处理时间搓
Vue.filter('dataFormat', function (originVal) {
	let dateTime = new Date(originVal);
	let y = dateTime.getFullYear(),
		m = (dateTime.getMonth() + 1 + '').padStart(2, '0'),
		// padStart() 方法用另一个字符串填充当前字符串
		d = (dateTime.getDate() + '').padStart(2, '0'),
		hh = (dateTime.getHours() + '').padStart(2, '0'),
		mm = (dateTime.getMinutes() + '').padStart(2, '0'),
		ss = (dateTime.getSeconds() + '').padStart(2, '0');

	return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
});

new Vue({
	router,
	store,
	render: (h) => h(App),
	// 全局事件总站
	beforeCreate() {
		Vue.prototype.$bus = this;
	},
}).$mount('#app');
